#include "stdafx.h"

namespace Help{
	System::String^ toSystemString(std::string s){
		//Convert from std string to System string
		System::String^ Temp = "";
		for (int i = 0; i < s.length(); i++){
			Temp += wchar_t(s[i]);
		}
		return Temp;
	}
	System::String^ toSystemString(char s[], int size){
		System::String^ Temp = "";
		for (int i = 0; i < size; i++){
			Temp += wchar_t(s[i]);
		}
		return Temp;
	}
	std::string toStdStirng(System::String^ s){
		std::string Temp = "";
		for (int i = 0; i < s->Length; i++){
			Temp += s[i];
		}
		return Temp;
	}
	std::string toStdStirng(char s[], int size){
		std::string Temp = "";
		for (int i = 0; i < size; i++){
			Temp += s[i];
		}
		return Temp;
	}
	char* toChar(std::string s){
		char* Temp = (char*)calloc(s.length(), sizeof(char*));
		for (int i = 0; i < s.length(); i++){
			if ((int)s[i] <= 255){
				Temp[i] = s[i];
			}
		}
		return Temp;
	}
	char* toChar(System::String^ s){
		char* Temp = (char*)calloc(s->Length, sizeof(char*));
		for (int i = 0; i < s->Length; i++){
			if (s[i] <= 255){
				Temp[i] = s[i];
			}
		}
		return Temp;
	}
	int toInt(std::string s){
		int Temp = 0;
		int::TryParse(toSystemString(s), Temp);
		return Temp;
	}
	int toInt(System::String^ s){
		int Temp = 0;
		int::TryParse(s, Temp);
		return Temp;
	}
	int toInt(char s[], int size){
		int Temp = 0;
		int::TryParse(toSystemString(s, size), Temp);
		return Temp;
	}
	float toFloat(std::string s){
		float Temp = 0;
		float::TryParse(toSystemString(s), Temp);
		return Temp;
	}
	float toFloat(System::String^ s){
		float Temp = 0;
		float::TryParse(s, Temp);
		return Temp;
	}
	float toFloat(char s[], int size){
		float Temp = 0;
		float::TryParse(toSystemString(s, size), Temp);
		return Temp;
	}
	int getIntInput(std::string s){
		std::string Temp = "";
		Temp.clear();
		std::cout << s;
		while (true){
			char t = _getch();
			if (t == 13){
				int v;
				std::istringstream ss(Temp);
				ss >> v;
				return v;
			}
			else if (t == 8){
				Temp = Temp.substr(0, Temp.length() - 1);
				system("cls");
				std::cout << s;
				std::cout << Temp;

			}
			else if (t < 58 && t >= 48 || t == 45){
				std::cout << t;
				Temp += (char)t;
			}
		}
	}
	float getFloatInput(std::string s){
		std::string Temp = "";
		Temp.clear();
		std::cout << s;
		while (true){
			char t = _getch();
			if (t == 13){
				float v;
				std::istringstream ss(Temp);
				ss >> v;
				return v;
			}
			else if (t == 8){
				Temp = Temp.substr(0, Temp.length() - 1);
				system("cls");
				std::cout << s;
				std::cout << Temp;
			}
			else if (t < 58 && t >= 48 || t == 46 || t == 45){
				std::cout << t;
				Temp += (char)t;
			}
		}
	}
	std::string getStringInput(std::string s){
		std::string Temp = "";
		std::cout << s;
		while (true){
			char t = _getch();
			if (t == 13){
				return Temp;
			}
			else if (t == 8){
				Temp = Temp.substr(0, Temp.length() - 1);
				system("cls");
				std::cout << s;
				std::cout << Temp;
			}
			else if (t <= 122 && t >= 33){
				std::cout << t;
				Temp += (char)t;
			}
		}

	}

}